package com.kuang.singleton;

import com.sun.xml.internal.bind.v2.runtime.unmarshaller.XsiNilLoader;

//单例模式的学习
//饿汉式
public class SingletonDemo01 {
    //1.私有化构造器
    private SingletonDemo01() {
    }
    //2。类初始化的时候，就加在这个对象
    private static SingletonDemo01 instance = new SingletonDemo01();
    //3.提供获取该对象的方法，
    public static SingletonDemo01 getSingletonDemo01(){
        return instance;
    }
}


class SingletonDemo01Test{
    public static void main(String[] args) {
        SingletonDemo01 instance1 = SingletonDemo01.getSingletonDemo01();
        SingletonDemo01 instance2 = SingletonDemo01.getSingletonDemo01();

        System.out.println(instance1==instance2);//true
    }
}

